export default {
  computed: {
    // 光缆详情绝对定位
    hoverPosition() {
      let top = null
      let bottom = null
      if (this.canvasHeight - this.hoverPositionTop - 78 > 0) {
        top = this.hoverPositionTop + 'px'
      } else {
        bottom = '0px'
      }
      // 获取当前鼠标在画布中的位置
      return {
        left: this.hoverPositionLeft + 'px', // 鼠标校准后的位置 140
        top: top,
        bottom: bottom
      }
    },
    // 点击光缆和节点弹出框位置
    clickPosition() {
      const objHeight = this.clickProp === 'selectEdge' ? 48 : 213
      let top = null
      let bottom = null
      if (this.canvasHeight - this.clickPositionTop - objHeight > 0) {
        top = this.clickPositionTop + 'px'
      } else {
        bottom = '0px'
      }
      // 获取当前鼠标在画布中的位置
      return {
        left: this.clickPositionLeft + 'px', // 鼠标校准后的位置
        top: top,
        bottom: bottom
      }
    }
  },
  data() {
    return {
      hoverProp: false,
      clickProp: '',
      associatedBusinessShow: false, // 关联业务弹窗
      associatedFaultBusinessShow: false, // 故障业务
      associatedRouteShow: false, // 关联路由弹窗
      associatedFaultRouteShow: false, // 故障路由
      deviceDetailShow: false, // 设备详情弹窗
      devicePortShow: false, // 设备端口详情
      cableDetailShow: false, // 光缆详情
      hoverPositionLeft: 0,
      hoverPositionTop: 0,
      clickPositionLeft: 0,
      clickPositionTop: 0,
      fiberInfo: {
        fiberNum: 0,
        bizNum: 0,
        idleNum: 0,
        damage: 0,
        backUp: 0
      },
      currentNode: {}, // 当前点击的节点
      currentEdge: {}, // 当前点击的边
      currentDevice: {},
      canvasHeight: 0
    }
  },
  methods: {
    hoverEdge(obj) {
      this.hoverProp = false
      this.fiberInfo = this.$options.data().fiber
      if (obj.mouseStatus === 'HOVER') {
        this.hoverProp = true
        const currFiber = this.edges.find(i => i.id === obj.id)
        this.fiberInfo = currFiber ? currFiber.subInfo : this.fiberInfo
      }
      this.hoverPositionLeft = obj.left
      this.hoverPositionTop = obj.top
    },
    selectEdge(obj) {
      this.clickProp = ''
      console.log('连接线...', obj)
      if (obj.mouseStatus === 'SELECT') {
        this.clickProp = 'selectEdge'
      }
      this.clickPositionLeft = obj.left
      this.clickPositionTop = obj.top
      this.currentEdge = obj
      // 根据边id筛选出网段两端的起始设备或光缆两端的站点和机房
    },
    selectNode(obj) {
      this.clickProp = ''
      if (obj.mouseStatus === 'SELECT') {
        this.clickProp = 'selectNode'
      }
      this.clickPositionLeft = obj.left
      this.clickPositionTop = obj.top
      this.currentNode = obj
      console.log('当前节点', this.canvasHeight)
    },
    // 关联业务click
    associatedBusinessClick(type) {
      this.associatedBusinessShow = true
    },
    // 故障业务click
    faultBusinessClick(type) {
      this.associatedFaultBusinessShow = true
      // this.$router.push({
      //   path: '/business/faultBusiness',
      //   query: {
      //     regionId: this.currentNode.nodeId || ''
      //   }
      // })
    },
    // 关联路由click
    associatedRouteClick(type) {
      if (type === 'EDAGE') {
        // 根据光缆id查故障业务
      } else if (type === 'NODE') {
        // 根据节点id查故障业务
      }
      this.associatedRouteShow = !this.associatedRouteShow
    },
    // 故障路由click
    faultRouteClick(type) {
      this.associatedFaultRouteShow = true
      // this.$router.push({
      //   path: '/business/faultRoute',
      //   query: {
      //     regionId: this.currentNode.nodeId || ''
      //   }
      // })
    },
    // 设备详情click
    deviceClick() {
      this.deviceDetailShow = !this.deviceDetailShow
    },
    // 光缆详情click
    cableDetailClick() {
      this.cableDetailShow = !this.cableDetailShow
    }
  },
  mounted() {}
}
